package sel.me.popular.library.learning.netty.reactor;

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.net.InetSocketAddress;

/**
 * @author shenenlu 2021年07月20日 上午11:45:46
 */
public class NettyReactor {

    private InetSocketAddress inetSocketAddress = new InetSocketAddress(8888);

    public static void main(String[] args) {


    }


    void singleThread(){
        //单线程模式
        Bootstrap b = new Bootstrap();
        EventLoopGroup eventLoopGroup = new NioEventLoopGroup(1);
        b.group(eventLoopGroup)
                .channel(NioSocketChannel.class)
                .option(ChannelOption.SO_KEEPALIVE, true)
                .remoteAddress(inetSocketAddress);
    }

    void multiThread(){
        //多线程模式
        ServerBootstrap b = new ServerBootstrap();
        EventLoopGroup acceptorLoopGroup = new NioEventLoopGroup(1);
        EventLoopGroup handlerLoopGroup = new NioEventLoopGroup();
        b.group(acceptorLoopGroup ,handlerLoopGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_KEEPALIVE, true)
//                .localAddress(8888)
                .bind(8888);
    }
}
